package cn.org.atool.generator.demo;

import cn.org.atool.generator.demo.dm.MyAddressDataMap;
import cn.org.atool.generator.demo.dm.NoAutoIdDataMap;
import cn.org.atool.generator.demo.dm.NoPrimaryDataMap;
import cn.org.atool.generator.demo.dm.StudentDataMap;
import cn.org.atool.generator.demo.mix.MyAddressTableMix;
import cn.org.atool.generator.demo.mix.NoAutoIdTableMix;
import cn.org.atool.generator.demo.mix.NoPrimaryTableMix;
import cn.org.atool.generator.demo.mix.StudentTableMix;
import java.util.List;
import org.test4j.module.database.IDataSourceScript;
import org.test4j.module.spec.internal.MixProxy;

/**
 * ATM: Application Table Manager
 *
 * @author Powered By Test4J
 */
@SuppressWarnings({"unused", "rawtypes"})
public interface ATM {
  DataMap dataMap = new DataMap();

  Table table = new Table();

  Mixes mixes = new Mixes();

  /**
   * 应用表名
   */
  class Table {
    public final String myAddress = "home_address";

    public final String student = "student";

    public final String noAutoId = "no_auto_id";

    public final String noPrimary = "no_primary";
  }

  /**
   * table or entity data构造器
   */
  class DataMap {
    public final MyAddressDataMap.Factory myAddress = new MyAddressDataMap.Factory();

    public final StudentDataMap.Factory student = new StudentDataMap.Factory();

    public final NoAutoIdDataMap.Factory noAutoId = new NoAutoIdDataMap.Factory();

    public final NoPrimaryDataMap.Factory noPrimary = new NoPrimaryDataMap.Factory();
  }

  /**
   * 应用表数据操作
   */
  class Mixes {
    public final MyAddressTableMix myAddressTableMix = MixProxy.proxy(MyAddressTableMix.class);

    public final StudentTableMix studentTableMix = MixProxy.proxy(StudentTableMix.class);

    public final NoAutoIdTableMix noAutoIdTableMix = MixProxy.proxy(NoAutoIdTableMix.class);

    public final NoPrimaryTableMix noPrimaryTableMix = MixProxy.proxy(NoPrimaryTableMix.class);

    public void cleanAllTable() {
      this.myAddressTableMix.cleanMyAddressTable();
      this.studentTableMix.cleanStudentTable();
      this.noAutoIdTableMix.cleanNoAutoIdTable();
      this.noPrimaryTableMix.cleanNoPrimaryTable();
    }
  }

  /**
   * 应用数据库创建脚本构造
   */
  class Script implements IDataSourceScript {
    @Override
    public List<Class> getTableKlass() {
      return list(
      	MyAddressDataMap.class,
      	StudentDataMap.class,
      	NoAutoIdDataMap.class,
      	NoPrimaryDataMap.class
      );
    }

    @Override
    public IndexList getIndexList() {
      return new IndexList();
    }
  }
}
